package com.polaris.live.adapter

import android.view.View
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterGiftDetailBinding
import com.polaris.live.resp.back_resp.GiftDetailResp
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * 礼物详情
 *
 * @author Created by 长空 on 2023/11/1/004 13:53
 */
class GiftDetailAdapter :
    BaseBindingAdapter<AdapterGiftDetailBinding, GiftDetailResp>() {

    override fun convert(holder: VBViewHolder<AdapterGiftDetailBinding>, item: GiftDetailResp) {
        holder.vb.apply {
            when (val position = holder.absoluteAdapterPosition) {
                0 -> {
                    ivRank.setImageResource(R.drawable.ic_rank_1)
                    ivRank.visibility = View.VISIBLE
                    tvRank.visibility = View.GONE
                }

                1 -> {
                    ivRank.setImageResource(R.drawable.ic_rank_2)
                    ivRank.visibility = View.VISIBLE
                    tvRank.visibility = View.GONE
                }

                2 -> {
                    ivRank.setImageResource(R.drawable.ic_rank_3)
                    ivRank.visibility = View.VISIBLE
                    tvRank.visibility = View.GONE
                }

                else -> {
                    ivRank.visibility = View.INVISIBLE
                    tvRank.visibility = View.VISIBLE
                    tvRank.text = position.toString()
                }
            }
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.avatarFrame))

            Glide.with(context).load(ImageUtils.imgPath(item.avatar)).normal().into(ivAvatar)
            tvName.text = item.nickname
            if (item.secondCountry?.isBlank() == true) {
                country.visibility = View.GONE
            } else {
                country.visibility = View.VISIBLE
                country.setCountry(item.secondCountry)
            }
            vipView.setVipLevel(item.vipLevel)
            level.setRichCharmBySexLevel(
                item.sex,
                item.richs,
                item.charms
            )
            tvNum.text = "x${item.num}"
        }
    }

}